package com.kanq.service.designpatterns.singleton;

/**
 * @Author cheng jun
 * @Description:饿汉式
 * @Date 2021/7/13 19:26
 */
public class Demo1 {
    private static final Demo1 INSTANCE = new Demo1();

    private Demo1() {
    }

    public static Demo1 getInstance() {
        return INSTANCE;
    }

    public static void main(String[] args) {
        Demo1 demo1 = Demo1.getInstance();
        Demo1 demo2 = Demo1.getInstance();
        Demo1 demo3 = new Demo1();
        System.out.println(demo1 == demo2);
        System.out.println(demo2 == demo3);

        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                System.out.println(getInstance().hashCode());
            }).start();
        }
    }
}
